<script setup>

import {ref} from "vue";
import axios from "axios";
import {myStore} from "@/accespt/myStore.js";
import {ElNotification} from "element-plus";

const ms = myStore();

const accountBean = ref({})
function login(){
  if (accountBean.value.username===undefined||accountBean.value.username===''){
    alert("用户名不能为空");
    return
  }
  if (accountBean.value.password===undefined||accountBean.value.password===''){
    alert("密码不能为空");
    return
  }
  axios.post('/api/login',accountBean.value)
      .then(res=>{
        const result = res.data;
        ElNotification({
          title: '提示',
          type: result.code===200?'success':'error',
          message: result.msg,
        })
        if (result.code===200){
          ms.token = result.data;
          ms.username = accountBean.value.username
        }else{
          ms.token = null;
        }
      })
}

</script>

<template>
<div class="container">
  <el-form :model="accountBean" label-width="auto" style="max-width: 300px">
    <el-form-item label="用户名">
      <el-input v-model="accountBean.username" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="accountBean.password" type="password" :show-password="true"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login">登录</el-button>
    </el-form-item>
  </el-form>
</div>

</template>

<style scoped>
.container{
  width: 100%;
  height: 80vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>